<?php

//home page
Route::get('/', function()
{
	return View::make('home.index');
});
Route::get('games', function()
{
  return Redirect::home();
});
//games categories page
Route::get('games/(:any)', array('as' => 'games', 'uses' => 'games@games'));
Route::get('games/new', array('as' => 'new', 'uses' => 'games@new'));
Route::post('games/create', array('uses' => 'games@create'));






Route::get('games/sport/(:any)', array('as' => 'game', 'uses' => 'game@game'));
Route::get('games/action/(:any)', array('as' => 'game', 'uses' => 'game@game'));
Route::get('games/puzzle/(:any)', array('as' => 'game', 'uses' => 'game@game'));
Route::get('games/racing/(:any)', array('as' => 'game', 'uses' => 'game@game'));
Route::get('games/strategy/(:any)', array('as' => 'game', 'uses' => 'game@game'));

Route::get('admin', array('as' => 'admin', 'uses' => 'admin@admin'));

//static pages
Route::get('about', array('as' => 'games', 'uses' => 'static@about'));
Route::get('contacts', array('as' => 'games', 'uses' => 'static@contacts'));
Route::get('description', array('as' => 'games', 'uses' => 'static@description'));

//auth. pages
Route::get('login', array('as' => 'login', 'uses' => 'login@index'));
Route::get('register', array('as' => 'register', 'uses' => 'login@signup'));
Route::post('login', function () {
        $user = array(
            'email' => Input::get('email'),
            'password' => Input::get('password')
        );
        if(User::ValidateCredentials($user['email'], $user['password']))
        return $user;
});
Route::post('register', function(){
  $user = new User();
  $user->nickName = Input::get('name');
  $user->email = Input::get('email');
  $user->password = $user->HashPassword(Input::get('password'));
  $user->Save();
});

Route::get('logout', array('as' => 'logout', 'uses' => 'logout@index', function()
{
  return View::make('login.index');
}));


/*
|--------------------------------------------------------------------------
| Application 404 & 500 Error Handlers
|--------------------------------------------------------------------------
|
| To centralize and simplify 404 handling, Laravel uses an awesome event
| system to retrieve the response. Feel free to modify this function to
| your tastes and the needs of your application.
|
| Similarly, we use an event to handle the display of 500 level errors
| within the application. These errors are fired when there is an
| uncaught exception thrown in the application.
|
*/

Event::listen('404', function()
{
	return Response::error('404');
});

Event::listen('500', function()
{
	return Response::error('500');
});

/*
|--------------------------------------------------------------------------
| Route Filters
|--------------------------------------------------------------------------
|
| Filters provide a convenient method for attaching functionality to your
| routes. The built-in before and after filters are called before and
| after every request to your application, and you may even create
| other filters that can be attached to individual routes.
|
| Let's walk through an example...
|
| First, define a filter:
|
|		Route::filter('filter', function()
|		{
|			return 'Filtered!';
|		});
|
| Next, attach the filter to a route:
|
|		Route::get('/', array('before' => 'filter', function()
|		{
|			return 'Hello World!';
|		}));
|
*/

Route::filter('before', function()
{
	// Do stuff before every request to your application...
});

Route::filter('after', function($response)
{
	// Do stuff after every request to your application...
});

Route::filter('csrf', function()
{
	if (Request::forged()) return Response::error('500');
});

Route::filter('auth', function()
{
	if (Auth::guest()) return Redirect::to('login');
});